/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ClassesJava;

import connexion.ConnectionManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author Administrateur
 */
public class Matiers {
    private int num;
	private int Nbheurs;
	private String label;
                 public ConnectionManager c;
	Matiers(int num,int Nbheurs,String label) {
		this.num = num;
		this.Nbheurs = Nbheurs;
		this.label =label;
	
}
	public int getNum() {
		return num;
	}
	public void setNum(int num) {
		this.num = num;
	}
	public int getNbheurs() {
		return Nbheurs;
	}
	public void setNbheurs(int Nbheurs) {
		this.Nbheurs = Nbheurs;
	}
	public String getlabel() {
		return label;
	}
	public void setlabel(String label) {
		this.label = label;
	}
	public int ajouterMat(Matiers m) {
        int i;
        c = new ConnectionManager();
        String rq = "INSERT INTO  `gestion_des_emplois`.`matiere` (idM , label , NbHeurs )"
                + " VALUES (NULL ,'" + m.getlabel()+ "', '" + m.getlabel() + "')";
        i = c.setDataBase(rq);
        return i;
            
        }
	public int modifierMat(Matiers m){
        int i = 0;
        c = new ConnectionManager();
        String rq = "UPDATE  `gestion_des_emplois`.`matiere` SET `NbHeurs` = '" + getNbheurs() + "', "
                + "`label` = '" + m.getlabel() + "' where idM=" + m.getNum();
        i = c.setDataBase(rq);
        
        return i;
       
        }
	public int supprimerMat(Matiers m){
            int i = 0;
        c = new ConnectionManager();
        String rq = "DELETE FROM `gestion_des_emplois`.`matiere where idM=" + m.getNum();
        i = c.setDataBase(rq);
       
       return i;
        }
	
    public Vector<Matiers> getMatiers() {
        Vector<Matiers> res = new Vector();
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("select * from matiere");

            while (rs.next()) {
                Matiers m = new Matiers(rs.getInt(1), rs.getInt(2), rs.getString(3));
                res.add(m);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Filiere.class.getName()).log(Level.SEVERE, null, ex);
        }

        return res;
        }
    
}
